package com.mallcai.bigdata.ladon.dpl.vo;

import org.apache.commons.lang3.StringUtils;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
public enum DatasourceType {
    MySQL("MySQL", "com.mysql.jdbc.Driver"),
    PostgreSQL("PostgreSQL", "org.postgresql.Driver"),
    ElasticSearch("ElasticSearch", "org.elasticsearch.xpack.sql.jdbc.EsDriver");


    private String code;
    private String driver;

    DatasourceType(String code, String driver) {
        this.code = code;
        this.driver = driver;
    }

    public String getCode() {
        return code;
    }

    public String getDriver() {
        return driver;
    }


    public static DatasourceType getByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }

        for (DatasourceType dt : DatasourceType.values()) {
            if (StringUtils.equalsIgnoreCase(dt.getCode(), code)) {
                return dt;
            }
        }

        return null;
    }
}
